﻿Public Class BCRanking
    Public Shared Function SalvarRanking(ByVal objBERanking As BE.BERanking) As String
        Dim objDARanking As New DA.DARanking
        Dim strIdRanking As String
        strIdRanking = objDARanking.Salvar(objBERanking)
        Return strIdRanking
    End Function
    Public Shared Sub DeletarRanking(ByVal strIdRanking As String)
        Dim objDARanking As New DA.DARanking
        Dim objDAMensagem As New DA.DAMensagem

        Dim objBERanking As BE.BERanking = objDARanking.Selecionar(strIdRanking)

        For Each objBERankeado As BE.BERankeado In objBERanking.Rankeados
            For Each objBEMensagem As BE.BEMensagem In objBERankeado.Mensagens
                objDARanking.ExcluirRelacionamento(strIdRanking, objBERankeado.CPF, objBEMensagem.Id)
                objDAMensagem.ExcluirMensagem(objBEMensagem)
            Next
            BCRankeado.DeletarRankeado(objBERankeado)
        Next

        objDARanking.Excluir(strIdRanking)
    End Sub

    Public Shared Function ListarMensagens(ByVal strIdRanking As String) As List(Of BE.BEMensagem)
        Dim objDAMensagem As New DA.DAMensagem
        Return objDAMensagem.ListarTodasAsMensagensDoRanking(strIdRanking, False)
    End Function

    Public Shared Function ListarRanking(ByVal booSomenteAtivos As Boolean) As List(Of BE.BERanking)
        Dim objDARanking As New DA.DARanking
        Dim objDAInscritos As New DA.DAInscritos
        Return IIf(booSomenteAtivos, objDARanking.ListarAtivos(), objDARanking.ListarInativos())
    End Function

    Public Shared Function SelecionarRanking(ByVal strIdRanking As String) As BE.BERanking
        Dim objDARanking As New DA.DARanking
        Dim objDAMensagem As New DA.DAMensagem

        Dim objBERanking As BE.BERanking

        objBERanking = objDARanking.Selecionar(strIdRanking)
        objBERanking.Rankeados = BCRankeado.ListarRankeados(strIdRanking)

        Return objBERanking
    End Function

End Class
